package com.xls.box2023.network;

import android.content.Context;

import com.lzz.bottomencapsulation.consts.NetConsts;
import com.lzz.bottomencapsulation.net.RetrofitBase;
import com.lzz.bottomencapsulation.utils.ImageUtils;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RequestManager {

    private static RequestManager requestManager;
    private static IApiserver apiService;

    private RequestManager(Context context) {
        if (null == requestManager || null == apiService) {
            apiService = RetrofitBase.getInstace(context).setBaseUrl(NetConsts.BASE_COM_URL).create(IApiserver.class);
        }
    }

    public static IApiserver getInstance(Context context) {
        if (requestManager == null) {
            synchronized (RequestManager.class) {
                requestManager = new RequestManager(context);
            }
        }
        return apiService;
    }

    public static RequestBody getTextBody(String content){
        return RequestBody.create(MediaType.parse("text/plain;charset=UTF-8"),content);
    }

    public static RequestBody getMP3Body(String filePath){
        return RequestBody.create(MediaType.parse("audio/aac;charset=UTF-8"), new File(filePath));
    }

    public static RequestBody getPngBody(String filePath){
        return RequestBody.create(MediaType.parse("image/png;charset=UTF-8"), new File(ImageUtils.compressImage(filePath, 80)));
    }
}
